11088 - End up with more teams (DP), 11282 - Mixing invitations & 1481 - Arrange...
[and.git] / Mi manual de algoritmos / version_maraton_interuniversitaria_2008-2 / src / number_theory / criba.tex
blobb2f29701e61d5b3a56ee88c3e09d8f860f23abb4
1 % Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
3 {\ttfamily \raggedright {
4 \noindent
5 \mbox{}\textbf{\textcolor{RoyalBlue}{\#include}}\ \texttt{\textcolor{Red}{$<$iostream$>$}} \\
6 \mbox{} \\
7 \mbox{}\textbf{\textcolor{Blue}{const}}\ \textcolor{ForestGreen}{int}\ SIZE\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{1000000}\textcolor{BrickRed}{;} \\
8 \mbox{} \\
9 \mbox{}\textit{\textcolor{Brown}{//criba[i]\ =\ false\ si\ i\ es\ primo}} \\
10 \mbox{}\textcolor{ForestGreen}{bool}\ criba\textcolor{BrickRed}{[}SIZE\textcolor{BrickRed}{+}\textcolor{Purple}{1}\textcolor{BrickRed}{];} \\
11 \mbox{} \\
12 \mbox{}\textcolor{ForestGreen}{void}\ \textbf{\textcolor{Black}{buildCriba}}\textcolor{BrickRed}{()}\textcolor{Red}{\{} \\
13 \mbox{}\ \ \textbf{\textcolor{Black}{memset}}\textcolor{BrickRed}{(}criba\textcolor{BrickRed}{,}\ \textbf{\textcolor{Blue}{false}}\textcolor{BrickRed}{,}\ \textbf{\textcolor{Blue}{sizeof}}\textcolor{BrickRed}{(}criba\textcolor{BrickRed}{));} \\
14 \mbox{} \\
15 \mbox{}\ \ criba\textcolor{BrickRed}{[}\textcolor{Purple}{0}\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ criba\textcolor{BrickRed}{[}\textcolor{Purple}{1}\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ \textbf{\textcolor{Blue}{true}}\textcolor{BrickRed}{;} \\
16 \mbox{}\ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ i\textcolor{BrickRed}{=}\textcolor{Purple}{4}\textcolor{BrickRed}{;}\ i\textcolor{BrickRed}{$<$=}SIZE\textcolor{BrickRed}{;}\ i\ \textcolor{BrickRed}{+=}\ \textcolor{Purple}{2}\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
17 \mbox{}\ \ \ \ criba\textcolor{BrickRed}{[}i\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ \textbf{\textcolor{Blue}{true}}\textcolor{BrickRed}{;} \\
18 \mbox{}\ \ \textcolor{Red}{\}} \\
19 \mbox{}\ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ i\textcolor{BrickRed}{=}\textcolor{Purple}{3}\textcolor{BrickRed}{;}\ i\textcolor{BrickRed}{*}i\textcolor{BrickRed}{$<$=}SIZE\textcolor{BrickRed}{;}\ i\ \textcolor{BrickRed}{+=}\ \textcolor{Purple}{2}\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
20 \mbox{}\ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(!}criba\textcolor{BrickRed}{[}i\textcolor{BrickRed}{])}\textcolor{Red}{\{} \\
21 \mbox{}\ \ \ \ \ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ j\textcolor{BrickRed}{=}i\textcolor{BrickRed}{*}i\textcolor{BrickRed}{;}\ j\textcolor{BrickRed}{$<$=}SIZE\textcolor{BrickRed}{;}\ j\ \textcolor{BrickRed}{+=}\ i\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
22 \mbox{}\ \ \ \ \ \ \ \ criba\textcolor{BrickRed}{[}j\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ \textbf{\textcolor{Blue}{true}}\textcolor{BrickRed}{;} \\
23 \mbox{}\ \ \ \ \ \ \textcolor{Red}{\}} \\
24 \mbox{}\ \ \ \ \textcolor{Red}{\}} \\
25 \mbox{}\ \ \textcolor{Red}{\}} \\
26 \mbox{}\textcolor{Red}{\}} \\
28 } \normalfont\normalsize